
{ Counts the number of black and white pixels in the current            }
{ selection and stores the results in the User1 and User2 columns   }

macro 'Count B&W Pixels [B]';
begin
  RequiresVersion(1.44);
  SetUser1Label('Black');
  SetUser2Label('White');
  Measure;
  rUser1[rCount]:=histogram[255];
  rUser2[rCount]:=histogram[0];
  UpdateResults;
end;



{ Counts the number of black and white pixels in the current           }
{ selection and stores the area % in the User1 and User2 columns    }

macro 'B&W as % [P]';
var
  sum:real;
begin
  RequiresVersion(1.44);       { copy image (or region) for analysis   }
  ScaleAndRotate(1,1,0);       { xscale=1, yscale=1, angle=0              }
  SetUser1Label('Black');
  SetUser2Label('White');
  ApplyLUT;                           { make the image B&W to count pixels  }
  Measure;
  sum:=histogram[0]+histogram[255];         { total number of pixels  }
  rUser1[rCount]:=histogram[255]*100/sum;
  rUser2[rCount]:=histogram[0]*100/sum;
  UpdateResults;
  Dispose;                             { get rid of temporary image  }
end;
